package com.bayes.teamshow.dao;

import com.bayes.teamshow.pojo.Article;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface ArticleSearch extends JpaRepository<Article,String>,PagingAndSortingRepository<Article,String>,JpaSpecificationExecutor<Article> {
    List<Article> findAll();

    @Query(value = "select   count(*) from Article",nativeQuery = true)
    Integer BlogCounts();


    Page<Article> findAll(Pageable pageable);//分页无条件查询

    Page<Article> findAll(Specification<Article> spec, Pageable pageable);  //分页按条件查询


    //根据ID删除博客
    @Modifying
    @Transactional
    @Query("delete  from Article  where id = ?1")
    public void deleteById(int id);

}


